<?php
require_once(DP_BASE_DIR."/modules/masterdata/mdcurrency.class.php");
$currency_id = intval( dPgetParam( $_GET, 'currency_id', 0 ) );

// check permissions for this record
/*
$perms =& $AppUI->acl();
if (! ($canEdit = $perms->checkModuleItem( 'currencys', 'edit', $currency_id )) ) {
	$AppUI->setMsg('Access denied', UI_MSG_ERROR);
	$AppUI->redirect();
}
*/

// load the record data
$msg = '';
$row = new CMdCurrency();

$canDelete = $row->canDelete( $msg, $currency_id );
if($msg == $AppUI->_('currencysDeleteUserError', UI_OUTPUT_JS)) {
	$userDeleteProtect=true;
}

if ($view) {
	$view = ' readonly="true"';
}
else {
	unset($view);
}

if (!$row->load( $currency_id ) && $currency_id > 0) {
	$AppUI->setMsg( 'Currency' );
	$AppUI->setMsg( 'invalidID', UI_MSG_ERROR, true );
	$AppUI->redirect();
}

$q = new DBQuery();
$q->addTable('md_currency');
$q->addQuery('currency_code');
if (isset($row->currency_code)) {
	$q->addWhere("currency_id != $row->currency_id");
}
$quoteCodeList = $q->loadColumn();
$qCL = '["' . implode('", "', $quoteCodeList) . '"]';

if (!$view) {
?>
<form name="MdCurrencyForm" action="?m=masterdata" method="post">
<input type="hidden" name="dosql" value="do_mdcurrency_aed" />
<input type="hidden" name="currency_id" value="<?=$currency_id?>" />
<?}?>
<table border="0" cellpadding="8" cellspacing="0" width="400px">
<tr>
<td colspan="2" bgcolor="#E0E0E0"><b><?=$AppUI->_('Currency Information')?></td>
</tr>
<tr>
	<td colspan="2">
		<table border="0" cellpadding="0" cellspacing="4" width="100%">
		<tr>
			<td align="right">* <?=$AppUI->_('Code')?></td>
			<td width="80%">
				<input type="text" class="text" name="currency_code" id="currency_code"
				value="<?=@$row->currency_code?>" maxlength="3" style="width: 98%" <?=$view?>/>
			</td>
		</tr>
		<tr>
			<td align="right">* <?=$AppUI->_('Name')?></td>
			<td>
				<input type="text" class="text" name="currency_name" id="currency_name"
					value="<?=@$row->currency_name?>" maxlength="50" style="width: 98%" <?=$view?>/>
			</td>
		</tr>
		<tr>
			<td align="right" nowrap="nowrap">* <?=$AppUI->_('Abbreviation')?></td>
			<td>
				<input type="text" class="text" name="currency_abbreviation" id="currency_abbreviation"
					value="<?=@$row->currency_abbreviation?>" maxlength="3" size="8" style="width: 30px" <?=$view?>/>
			</td>
		</tr>
		<tr>
			<td align="right"><?=$AppUI->_('Active')?></td>
			<td>
				<input type="checkbox" name="currency_active"
					value="<?=@$row->currency_active?>" maxlength="50" <?=$view?> <?= (@$row->currency_active == 1) ? "checked":""?>/>
			</td>
		</tr>
		</table>
	</td>
</tr>
<tr>
	<td align="center" colspan="2" style="border-top: 1px solid #E0E0E0">
	<? if (!$view) { ?>
		<input type="submit" class="button" value="<?=$AppUI->_('Save')?>"/>
		<input type="button" class="button" value="<?=$AppUI->_('Cancel')?>" onClick="doCloseCurrency()"/>
	<? } else { ?>
		<input type="button" class="button" value="<?=$AppUI->_('Close')?>" onClick="doCloseCurrency()"/>
	<? } ?>
	</td>
</tr>
</table>
</form>
<div id="validation_rules" style="visibility: hidden; display: none">
	var fCurrencyCode = new LiveValidation('currency_code');
	fCurrencyCode.add(Validate.Presence );
	fCurrencyCode.add( Validate.Exclusion , {within: <?=$qCL?>});

	var fCurrencyName = new LiveValidation('currency_name');
	fCurrencyName.add(Validate.Presence );

	var fCurrencyAbbreviation = new LiveValidation('currency_abbreviation');
	fCurrencyAbbreviation.add(Validate.Presence );

	new Tips($$('.text'));
</div>
